<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        报修编辑
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <script type="text/javascript" src="lib/loading/okLoading.js"></script>
    <style>
        .imgs{display: none;}
    </style>

</head>
<body>

<div class="x-body">
    <form class="layui-form layui-form-pane"  action="${pageContext.request.contextPath}/RepairServlet" method="post" id="addPay-form">
         <input type="hidden" name="op" id="op" value="payAdd">
         <input type="hidden" name="repairStatus" id="repairStatus" value="">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">											


            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                   

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>报修编号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="repairNo" autocomplete="off" 
                                   class="layui-input" readonly="readonly" value="">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>房间号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="roomNo" autocomplete="off" 
                                   class="layui-input" readonly="readonly" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>报修时间
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="repairCreateTime" autocomplete="off" 
                                   class="layui-input" readonly="readonly" value="">
                        </div>
                    </div>
                   
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>处理时间
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="repairDealTime" autocomplete="off" 
                                   class="layui-input" readonly="readonly" value="">
                        </div>
                    </div>

                     <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>处理人
                        </label>
                        <div class="layui-input-block">
                            <input type="text" readonly="readonly" name="repairHandler" id="repairHandler" placeholder="" autocomplete="off" 
                                   class="layui-input"  value="">
                        </div>
                    </div>
                    

                    

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>报修描述
                        </label>
                        <div class="layui-input-block">
                            <textarea readonly="readonly" placeholder="请输入内容" id="repairContent" class="layui-textarea"></textarea>
                        </div>
                    </div>
                     <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>报修金额
                        </label>
                        <div class="layui-input-block">
                            <input id="payMoney" type="text" name="payMoney" autocomplete="off" 
                                   class="layui-input"  value="">
                        </div>
                    </div>

					<div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>缴费单号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="payNo" readonly="readonly" autocomplete="off" 
                                   class="layui-input"  value="">
                        </div>
                    </div>
					
                    <div class="layui-form-item">
                        <button class="layui-btn" id="addPayBtn" type="submit" >
                            生成缴费单
                        </button>
                    </div>
                    <!--</form>-->
                    <div  style="height:100px;"></div>
                </div>



            </div>

        </div>
    </form>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
<script src="js/jquery.min.js" charset="utf-8"></script>
<script src="js/jquery-form.js" charset="utf-8"></script>
<script>
	let repairNo = "${param.repairNo}";
	
	
	$.getJSON("${pageContext.request.contextPath}/RepairServlet",{op:"repairEdit",repairNo:repairNo},function(result,status,xhr){
		
		let roomNo = result.data.roomNo;
		let repairCreateTime = result.data.repairCreateTime.replace("T"," ");
		let repairDealTime = result.data.repairDealTime;
		let repairContent = result.data.repairContent;
		let repairHandler = result.data.repairHandler;
		let payNo = result.data.payNo;
		let payMoney = result.data.pay.payMoney;
		
		if(payMoney == null || "" == payMoney){
			
			$("#payMoney").prop("placeholder", "暂无缴费金额");
			
		}else{
			$("#payMoney").prop("readonly", "readonly");
		}
		if(payNo == null || ""==payNo){
			payNo = "暂无缴费单号";
		}
		
		if(repairDealTime == null || ""==repairDealTime){
			repairDealTime = "暂无时间";
		}else{
			repairDealTime = result.data.repairDealTime.replace("T", " ")
		}
		if(repairHandler == null || ""==repairHandler){
			$("#repairHandler").prop("placeholder","暂无处理人");
		}
		let repairStatus = result.data.repairStatus;
		
		
		$("input[name='repairStatus']").val(repairStatus);
		$("input[name='payMoney']").val(payMoney);
		$("input[name='payNo']").val(payNo);
		$("input[name='repairNo']").val(repairNo);
		$("input[name='roomNo']").val(roomNo);
		$("input[name='repairCreateTime']").val(repairCreateTime);
		$("input[name='repairDealTime']").val(repairDealTime);
		$("#repairContent").val(repairContent);
		$("input[name='repairHandler']").val(repairHandler);
		$("input[name='repairDealTime']").val(repairDealTime);
		
		console.log();
		
	});
	
	
	//表单异步提交
	//表单异步提交
	$("#addPay-form").submit(function(){
		if($("input[name='repairStatus']").val() != 03){
			layui.use('layer',function(){
    			layer.msg("报修状态不是已维修，无法生成！",{icon:5,time:3000});
    		});
			
		}else{
			$(this).ajaxSubmit(function(result){
				//用layui弹出
				if(result.status != 0){
					layui.use('layer',function(){
		    			layer.msg(result.message,{icon:1,time:3000});
		    		});
					
		    		 setTimeout(function(){
		    			//关闭子窗口                调用父亲的查询方法
		    	    		window.parent.repair_search_page();
		    	    		var index = parent.layer.getFrameIndex(window.name);
		    	            parent.layer.close(index);
		    		 },3000);
				}else{
					layui.use('layer',function(){
		    			layer.msg(result.message,{icon:5,time:3000});
		    		});
				}
	    		
				
	           
	    		
			});
		}
		
		return false;
	});
</script>

<script>
    $(function () {
        var username="xiyuan";
        //var username="惜缘";
        $("input[name='uasername']").val(username);
    })
</script>
<script>
    layui.use(['laydate','element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        okLoading.close($);
        form.render();



        //监听提交
        form.on('submit(add)', function(data){

            var uasername=$("input[name='uasername']").val();
            var device_name=$("input[name='device_name']").val();

            var community_id=$('#community_id option:selected') .val();//所属栏目ID
            if(community_id==""){
                layer.msg('所属小区不能为空',{icon:5,time:2000});return false;
            }
            if(uasername==""){
                layer.msg('报修人员不能为空',{icon:5,time:2000});return false;
            }
            if(device_name==""){
                layer.msg('设备名称不能为空',{icon:5,time:2000});return false;
            }
            var data=data.field;
            $.ajax({
                type:"post",
                url:"xxx",
                data:data,
                dataType:"json",
                success:function(data){
                    if(data.status==1)
                    {
                        layer.msg(data.info, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;

                    }
                    else{
                        layer.msg(data.info,{icon:5,time:2000});return false;
                    }
                }

            });

        });

    })
</script>
<!--栏目缩略图上传-->
<script>
    function upload()
    {
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        //console.log(formData);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"xxx",
            data:formData,
            success:function(data){
                if(data.status == 1){
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src',data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            }
        });
    }
</script>

</body>
</html>